﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

/*
 * Author:Conis
 * Date:
 * Description:Xml的根节点
 */

namespace Coins.Squirrel.Nodous.Xml
{
    public class XmlNodousRoot : XmlNodousNode, INodousRoot
    {
        private string returnString;
        #region 普通方法
        /// <summary>
        /// 创建根节点
        /// </summary>
        /// <param name="name"></param>
        public XmlNodousRoot(string name)
            : base(name)
        {
            this.container = new XmlDocument();
        }

        /// <summary>
        /// 创建节点，创建节点的文档说明及根节点
        /// </summary>
        protected override void CreateNode()
        {
            XmlDeclaration dec = this.container.CreateXmlDeclaration("1.0", "UTF-8", null);
            this.container.AppendChild(dec);
            XmlElement element = this.container.CreateElement(this.name);
            this.parentElement = element;
            this.container.AppendChild(element);
        }
        #endregion

        #region INodousRoot 成员
        /// <summary>
        /// 返回生成的字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.returnString;
        }

        /// <summary>
        /// 创建节点
        /// </summary>
        public new void Create()
        {
            base.Create();
            this.returnString = this.container.OuterXml;
        }

        #endregion
    }
}
